package com.ruoyi.web.controller.record;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.record.domain.AllotRecord;
import com.ruoyi.record.service.IAllotRecordService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;

import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 调拨记录Controller
 * 
 * @author cy
 * @date 2024-11-05
 */
@RestController
@RequestMapping("/inventory/record")
public class AllotRecordController extends BaseController
{
    @Autowired
    private IAllotRecordService allotRecordService;

    /**
     * 查询调拨记录列表
     */
    @PreAuthorize("@ss.hasPermi('inventory:record:list')")
    @GetMapping("/list")
    public TableDataInfo list(AllotRecord allotRecord)
    {
        startPage();
        List<AllotRecord> list = allotRecordService.selectAllotRecordList(allotRecord);
        return getDataTable(list);
    }

    /**
     * 导出调拨记录列表
     */
    @PreAuthorize("@ss.hasPermi('inventory:record:export')")
    @Log(title = "调拨记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AllotRecord allotRecord)
    {
        List<AllotRecord> list = allotRecordService.selectAllotRecordList(allotRecord);
        ExcelUtil<AllotRecord> util = new ExcelUtil<AllotRecord>(AllotRecord.class);
        util.exportExcel(response, list, "调拨记录数据");
    }

    /**
     * 获取调拨记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('inventory:record:query')")
    @GetMapping(value = "/{document}")
    public AjaxResult getInfo(@PathVariable("document") String document)
    {
        return success(allotRecordService.selectAllotRecordByDocument(document));
    }

    /**
     * 新增调拨记录
     */
    @PreAuthorize("@ss.hasPermi('inventory:record:add')")
    @Log(title = "调拨记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AllotRecord allotRecord)
    {
        return toAjax(allotRecordService.insertAllotRecord(allotRecord));
    }

    /**
     * 修改调拨记录
     */
    @PreAuthorize("@ss.hasPermi('inventory:record:edit')")
    @Log(title = "调拨记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AllotRecord allotRecord)
    {
        return toAjax(allotRecordService.updateAllotRecord(allotRecord));
    }

    /**
     * 删除调拨记录
     */
    @PreAuthorize("@ss.hasPermi('inventory:record:remove')")
    @Log(title = "调拨记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{documents}")
    public AjaxResult remove(@PathVariable String[] documents)
    {
        return toAjax(allotRecordService.deleteAllotRecordByDocuments(documents));
    }
}
